package com.jingdianjichi.wx.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.time.Instant;
import java.time.LocalDateTime;
import java.util.Map;
import java.util.Random;

@Slf4j
@Component
public class SubscribeMessageHandle implements WxChatMsgHandler {

    @Override
    public WxChatMsgTypeEnum getMsgType() {
        return WxChatMsgTypeEnum.SUBSCRIBE;
    }


    @Override
    public String dealMsg(Map<String,String> messageMap) {
        log.info("触发用户关注事件，");

        String fromUserName = messageMap.get("FromUserName");
        String toUserName = messageMap.get("ToUserName");
        String subscribeContent = "感谢您的关注，我是坤坤，欢迎来学习姬霓太美";
        LocalDateTime now = LocalDateTime.now();

        String content = "<xml>\n" +
                "<ToUserName><![CDATA["+fromUserName+"]]></ToUserName>\n" +
                "<FromUserName><![CDATA["+toUserName+"]]></FromUserName>\n" +
                "<CreateTime><![CDATA["+now+"]]></CreateTime>\n" +
                "<MsgType><![CDATA[text]]></MsgType>\n" +
                "<Content><![CDATA["+subscribeContent+"]]></Content>\n"+
                "</xml>";
        return content;
    }
}
